home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1990-10-22 | 11.6 KB | 266 lines | [ TEXT/PJMM]
{****************************************************} {} { CLottoConfigure.p } {} {} { Copyright © 1990, Stanley Fertig. All rights reserved. } {} {****************************************************} unit CLottoConfigure; {Dialog objects to enable user to configure the choices of Lotto numbers.} interface uses TCL, sfCL, LottoIntf; {----------------------------------------------------------------------------} implementation procedure CLottoConfigure.ILottoConfigure; {Initialize director for nonmodal Dialog} var aDial: CLottoConfigureDial; begin IDirector(gApplication); {Be sure to call the default method first} new(aDial); {Create & initialize dialog window object} itsWindow := aDial; aDial.IDialog(integer(cmdConfigure), false, gDesktop, Self, false, true); itsGopher := Self; gGopher := itsGopher; CLottoDoc(gDocument).fConfigure := Self {Tell Lotto document we exist} end; {----------------------------------------------------------------------------} procedure CLottoConfigure.Free; begin CLottoDoc(gDocument).fConfigure := nil; {Before we disappear, warn the Lotto Document about it} inherited Free end; {----------------------------------------------------------------------------} procedure CLottoConfigure.Dawdle (var maxSleep: longint); {Blink cursor at insertion point if needed} begin if not gInBackground & (CLottoConfigureDial(itsWindow).macPort = FrontWindow) & (DialogPeek(CLottoConfigureDial(itsWindow).macPort)^.editField > -1) then begin TEIdle(DialogPeek(CLottoConfigureDial(itsWindow).macPort)^.textH); maxSleep := GetCaretTime end end; {----------------------------------------------------------------------------} procedure CLottoConfigure.UpdateMenus; var i: shortint; FontMenu: MenuHandle; begin inherited UpdateMenus; {Do standard menu updates} FontMenu := GetMHandle(MenuFont); {Get handle to Font menu} CDialog(Self.itsWindow).UpdateEdit; {Update Edit menu items accordingly} if not gInBackground then gBartender.EnableCmd(cmdHelp); {enable the Help menu command} gBartender.DisableCmd(cmdConfigure); {Disable commands which are meaningless} gBartender.DisableCmd(cmdNew); {if Configure dialog is topmost.} gBartender.DisableCmd(cmdPageSetup); gBartender.DisableCmd(cmdPrint); gBartender.DisableCmd(cmdFontSizeDial); for i := 1 to CountMItems(FontMenu) do {Disable all font items on Font menu} DisableItem(FontMenu, i) end; {----------------------------------------------------------------------------} procedure CLottoConfigureDial.IDialog (DIALid: integer; {Initialize the Dialog window object} aFloating: Boolean; anEnclosure: CDesktop; aSupervisor: CBureaucrat; Beep, DoCenter: boolean); const UserNumber = 2; {ID# for userItem for highlighting default OK box} UniverseNumber = 4; {Textbox for number of potential numbers to choose from} ChoiceNumber = 5; {Textbox for number of numbers to choose} checkBoxNumber = 6; {Checkbox for choosing numbers With or Without Replacement} var aUniverse, aNumbChoices: str255; theType: integer; theItemHandle: Handle; theBox: Rect; theCheckBox: ControlHandle; begin inherited IDialog(DIALid, aFloating, anEnclosure, aSupervisor, Beep, DoCenter); {standard Dialog window initialize} aUniverse := stringof(CLottoDoc(gDocument).fUniverse : 1); {Initialize universe to Lotto's existing universe of numbers.} aNumbChoices := stringof(CLottoDoc(gDocument).fNumbChoices : 1); {Initialize # of choices to Lotto's existing # of choices.} GetDItem(Self.macPort, UserNumber, theType, theItemHandle, theBox); {Get handle to OK button} SetDItem(Self.macPort, UserNumber, theType, @SelectButton, theBox); {Hilite OK button via userItem} GetDItem(Self.macPort, UniverseNumber, theType, theItemHandle, theBox); SetIText(theitemHandle, aUniverse); {Put universe in appropriate textbox} GetDItem(Self.macPort, ChoiceNumber, theType, theItemHandle, theBox); SetIText(theitemHandle, aNumbChoices); {Put # choices in appropriate textbox} SelIText(Self.macPort, ChoiceNumber, kSelStart, kSelEnd); {Select this text to start} GetDItem(Self.macPort, checkBoxNumber, theType, theItemHandle, theBox); {Get handle to checkbox} theCheckBox := ControlHandle(theitemHandle); {Convert to Control Handle} if CLottoDoc(gDocument).fWithReplacement then {Check or uncheck box, as per existing Lotto setting} SetCtlValue(theCheckBox, 1) else SetCtlValue(theCheckBox, 0); Self.Select {Activate the Dialog box object on the screen} end; {----------------------------------------------------------------------------} function CLottoConfigureDial.Filter (thedial: DialogPtr; var anEvent: EventRecord; var itemNumber: integer): boolean; var chCode: integer; ch: char; cmdDown: boolean; begin if anEvent.what in [keydown, AutoKey] then begin Filter := true; with anEvent do begin chCode := BitAnd(message, CharCodeMask); ch := chr(chCode); cmdDown := (BitAnd(modifiers, CmdKey) <> 0) end; if not cmdDown then begin if (chCode in [$8, $9, $3, $D, $30..$39]) then {List your 'Acceptable' keys here} Filter := inherited Filter(thedial, anEvent, itemNumber) else begin Sysbeep(1); itemNumber := 0; end end else {if Command Key is down} Filter := inherited Filter(thedial, anEvent, itemNumber) end else {if not Keyboard Event} Filter := inherited Filter(thedial, anEvent, itemNumber) end; {----------------------------------------------------------------------------} procedure CLottoConfigureDial.DoDialog (anEvent: EventRecord); {After dialog box on screen, respond to User actions} const checkBoxNumber = 6; cancelNumber = 3; var theItem: integer; FiltItemNumber: integer; theCheckBox: ControlHandle; theItemHandle: Handle; theType: integer; theBox: Rect; oldValue: integer; theString: str255; dPtr: DialogPtr; FilterResult: boolean; begin Prepare; {Set port & Clipping to our dialog box} theItem := 0; {Initialize to no User action} FilterResult := false; {Initialize to no keyboard action} GetDItem(Self.macPort, checkBoxNumber, theType, theItemHandle, theBox); {Get handle to Checkbox} theCheckBox := ControlHandle(theitemHandle); {Convert to Control Handle} if anEvent.what in [Keydown, AutoKey] then {User typed something?} begin dPtr := Self.macPort; {Need DialogPtr for Filter functions.} FilterResult := Self.Filter(dPtr, anEvent, FiltItemNumber) {Filter function for special keyboard items} end; if FilterResult then {Filter returned positive result, i.e. meaningful keyboard entry} case FiltItemNumber of {Which keyboard command did User type?} AltcmdQuit: {User typed Command-Q} gApplication.DoCommand(cmdQuit); {Let's quit the Application.} cmdHelp: {User hit 'Help' key on Ext. keyboard, or Command-H} gApplication.DoCommand(FiltItemNumber); {Bring up 'Help' Dialog.} cancelNumber: {User hit 'escape' button} Self.Close; {Close dialog box and kill this object} OK: {User hit 'Enter' or 'Return} begin GetDItem(Self.macPort, 4, theType, theItemHandle, theBox); {Get handle to textbox} GetIText(theitemHandle, theString); {Get text from textbox} oldValue := IntVal(theString); {Convert string to integer} if oldValue in [1..maxChoices] then {Is integer acceptable?} CLottoDoc(gDocument).fUniverse := oldValue {Set universe size to integer} else Sysbeep(1); GetDItem(Self.macPort, 5, theType, theItemHandle, theBox); {Get handle to textbox} GetIText(theitemHandle, theString); {Get text from textbox} oldValue := IntVal(theString); {Convert string to integer} if oldValue in [1..CLottoDoc(gDocument).fUniverse] then {Is integer acceptable?} CLottoDoc(gDocument).fNumbChoices := oldValue {Set # choices to integer} else Sysbeep(1); CLottoDoc(gDocument).fWithReplacement := GetCtlValue(theCheckBox) = 1; {Set Lotto's replacement option based on whether option checked} Self.Close {Close dialog box and kill this object} end; otherwise end {of Case} else {Filter returned negative result, i.e. no acceptable key entry} begin if anEvent.what = UpDateEvt then Self.Update {Update dialog box if necessary.} else if anEvent.what = ActivateEvt then if BitAnd(anEvent.modifiers, ActiveFlag) = 1 then {Activate dialog box or deactivate if need be} Self.Activate else Self.Deactivate else if DialogSelect(anEvent, dPtr, theItem) then {User clicked in enabled Item?} case theItem of cancelNumber: {User clicked in Cancel button} Self.Close; {Close dialog box and kill this object} OK: {User clicked in OK button} begin GetDItem(Self.macPort, 4, theType, theItemHandle, theBox); {Get handle to textbox} GetIText(theitemHandle, theString); {Get text from textbox} oldValue := IntVal(theString); {Convert string to integer} if oldValue in [1..maxChoices] then {Is integer acceptable?} CLottoDoc(gDocument).fUniverse := oldValue {Set universe size to integer} else Sysbeep(1); GetDItem(Self.macPort, 5, theType, theItemHandle, theBox); {Get handle to textbox} GetIText(theitemHandle, theString); {Get text from textbox} oldValue := IntVal(theString); {Convert string to integer} if oldValue in [1..CLottoDoc(gDocument).fUniverse] then {Is integer acceptable?} CLottoDoc(gDocument).fNumbChoices := oldValue {Set # choices to integer} else Sysbeep(1); CLottoDoc(gDocument).fWithReplacement := GetCtlValue(theCheckBox) = 1; {Set Lotto's replacement option based on whether option checked} Self.Close {Close dialog box and kill this object} end; checkBoxNumber: {User clicked in Checkbox} begin oldValue := GetCtlValue(theCheckBox); {Get Checkbox value before Click} SetCtlValue(theCheckBox, 1 - oldValue) {Toggle to other value} end; otherwise end {of CASE} end end; {----------------------------------------------------------------------------} end.